<template>
  <div class="stock-group-item">
    <div
      class="select-block"
      :class="{ actived: isActived, 'cursor-pointer': carModelStockState.selector != null }"
      @click="selectCarModel"
    >
      <div class="car-model-header">
        <div class="car-model-header-title">
          <a-radio class="mr-2.5" :model-value="isActived" size="large" v-if="carModelStockState.selector" />
          <div>{{ data.modelName }}</div>
          <div class="more-tag" v-if="isMore"> 超卖 </div>
        </div>

        <div class="car-model-header-collapse" @click.stop="collapseChange">
          {{ collapse ? '收起' : '展开' }}
          <icon-down class="collapse-icon" :class="{ 'collapse-icon-expand': collapse }" />
        </div>
      </div>
      <div class="total-block">
        库存：{{ data.useNum }}/{{ data.stockNum }}
        <a-tooltip content="X/Y X为当前订单占用此车型数量；Y为当前门店此车型对应车辆总数">
          <icon-question-circle style="font-size: 16px" />
        </a-tooltip>
      </div>
    </div>
    <!-- 车牌 -->
    <div class="car-list" v-if="collapse">
      <div class="divider"></div>
      <a-empty v-if="data.carList.length == 0" />
      <div class="car-item tag-item" :class="['tag_' + car.type]" v-for="car in data.carList" :key="car.carId">
        <div class="licenseNo">
          <a-typography-paragraph
            class="licenseNo-text"
            :ellipsis="{
              showTooltip: true,
            }"
          >
            {{ car.licenseNo }}
          </a-typography-paragraph>
        </div>
        <div>{{ car.typeName }} </div>
      </div>
    </div>
  </div>
</template>

<script lang="ts">
  import { computed, inject, ref } from 'vue'
  export default {
    props: {
      data: Object,
    },
    setup(props) {
      const carModelStockState = inject('carModelStockState') as any
      const pickerValue = ref()
      const collapse = ref(false)
      const collapseChange = () => {
        collapse.value = !collapse.value
      }
      const isActived = computed(() => {
        if (!carModelStockState.selector) return false
        return carModelStockState.selector.id == props.data.id
      })
      // 是否超卖
      const isMore = props.data.useNum > props.data.stockNum

      const selectCarModel = () => {
        if (!carModelStockState.selector) return false
        carModelStockState.selector.id = props.data.id
        carModelStockState.selector.carModel = props.data
      }
      return {
        isActived,
        isMore,
        collapse,
        carModelStockState,
        pickerValue,
        collapseChange,
        selectCarModel,
      }
    },
  }
</script>

<style lang="less" scoped>
  .stock-group-item {
    border: 1px solid #f2f3f5;
    border-radius: 4px;
    padding: 10px;
    margin-bottom: 20px;
    .select-block {
      padding: 10px;
      border-radius: 4px;

      &.actived {
        outline: 1px solid #1890ff;
        background: #e8f3ff;
      }
    }
  }
  .car-list {
    display: flex;
    flex-wrap: wrap;
    @import '../../cz_tag.less';

    .tag-item {
      position: relative;
      width: 131px;
      height: 49px;
      padding: 5px 16px 0;
      overflow: hidden;

      &::before {
        content: '';
        display: block;
        position: absolute;
        top: 0;
        left: 0;
        width: 4px;
        height: 49px;
      }
    }

    .car-item {
      margin-top: 10px;
      margin-right: 10px;
      .licenseNo {
        &-text {
          font-size: 14px;
          color: #1d2129;
          margin-bottom: 2px;
          line-height: 20px;
        }
      }
      overflow: hidden;
      white-space: nowrap;
      font-size: 12px;
      color: #86909c;
      line-height: 17px;
    }
    .divider {
      width: 100%;
      height: 1px;
      background: #f2f3f5;
    }
  }

  .car-model-header {
    position: relative;
    padding-right: 100px;
    &-title {
      display: flex;
      font-size: 16px;
      font-weight: 600;
      color: #1d2129;
      line-height: 22px;
      align-items: center;

      .more-tag {
        flex-shrink: 0;
        margin-left: 10px;
        width: 40px;
        height: 18px;
        background: linear-gradient(58deg, #ff5b60 0%, #ff7a66 100%);
        border: 1px solid #ffffff;
        border-radius: 20px;
        // 字
        text-align: center;
        font-size: 12px;
        font-weight: 400;
        color: #ffffff;
        line-height: 17px;
      }
    }
    &-collapse {
      position: absolute;
      right: 0px;
      top: 0px;
      cursor: pointer;
      // 字
      font-size: 14px;
      color: #1890ff;
      line-height: 24px;

      .collapse-icon {
        transition: transform 0.2s cubic-bezier(0.34, 0.69, 0.1, 1);
        &-expand {
          transform: rotate(180deg);
        }
      }
    }
  }

  .total-block {
    margin-top: 10px;
    font-size: 14px;
    font-weight: 400;
    color: #4e5969;
    line-height: 20px;
  }
</style>
